﻿using PLCTest.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;

namespace PLCTest.BO
{
    public class MatterPlanarGeneralWriteWcsAction
    {
        public MatterPlanarGeneralWriteWcsAction() { }
        public MatterPlanarGeneralWriteWcsAction(
            int equipmentCode
            , int taskCode
            , int toEquipmentCode
            , string palletBarcode
            , short palletWeight
            , short actionType
            , byte palletType
            , byte alrmCode
            , byte signalTask = 0
            , byte reserve2 = 0
            , byte reserve3 = 0
            , byte reserve4 = 0)
        {

            EquipmentCode = equipmentCode.ToString();   //设备号
            TaskCode = taskCode;  //任务号
            ToEquipmentCode = toEquipmentCode;  //目标设备号
            PalletBarcode = palletBarcode;  //托盘码
            PalletWeight = palletWeight;  //托盘重量
            ActionType = actionType;  //握手类型
            PalletType = palletType;  //托盘类型
            AlrmCode = alrmCode;  //报警代码
            SignalTask = signalTask;  //是否单机任务
            Reserve2 = reserve2;  //预留2
            Reserve3 = reserve3;  //预留3
            Reserve4 = reserve4;  //预留4
        }

        /// <summary>
        /// 当前设备号
        /// </summary>
        public string EquipmentCode { get; set; }
        /// <summary>
        /// 任务编号
        /// </summary>
        public int TaskCode { get; set; }
        /// <summary>
        /// 目标设备号
        /// </summary>
        public int ToEquipmentCode { get; set; }
        /// <summary>
        /// 托盘码
        /// </summary>
        public string PalletBarcode { get; set; }
        /// <summary>
        /// 托盘重量
        /// </summary>
        public short PalletWeight { get; set; }
        /// <summary>
        /// 握手类型
        /// </summary>
        public short ActionType { get; set; }
        /// <summary>
        /// 托盘类型
        /// </summary>
        public byte PalletType { get; set; }
        /// <summary>
        /// 故障代码
        /// </summary>
        public byte AlrmCode { get; set; }
        /// <summary>
        /// 是否单机任务
        /// </summary>
        public byte SignalTask { get; set; }
        /// <summary>
        /// 预留2
        /// </summary>
        public byte Reserve2 { get; set; }
        /// <summary>
        /// 预留3
        /// </summary>
        public byte Reserve3 { get; set; }
        /// <summary>
        /// 预留4
        /// </summary>
        public byte Reserve4 { get; set; }

        public byte[] Deserialize()
        {

            byte[] bytes = new byte[42];
            HelperByte.SetDIntAt(bytes, 0, EquipmentCode.ToInt32());
            HelperByte.SetDIntAt(bytes, 4, TaskCode);
            HelperByte.SetDIntAt(bytes, 8, ToEquipmentCode);
            HelperByte.SetByteAt(bytes, 12, 18);
            byte length = Convert.ToByte(PalletBarcode.Length);
            HelperByte.SetByteAt(bytes, 13, length);
            HelperByte.SetCharsAt(bytes, 14, PalletBarcode);
            HelperByte.SetIntAt(bytes, 32, PalletWeight);
            HelperByte.SetIntAt(bytes, 34, ActionType);
            HelperByte.SetByteAt(bytes, 36, PalletType);
            HelperByte.SetByteAt(bytes, 37, AlrmCode);
            HelperByte.SetByteAt(bytes, 38, SignalTask);
            HelperByte.SetByteAt(bytes, 39, Reserve2);
            HelperByte.SetByteAt(bytes, 40, Reserve3);
            HelperByte.SetByteAt(bytes, 41, Reserve4);

            return bytes;
        }

    }
}
